/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.powerhua.fms.dao.impl;

import com.powerhua.fms.dao.IFileDao;
import com.powerhua.fms.domain.FileBean;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.jdbc.core.RowMapperResultReader;
import org.springframework.jdbc.core.support.JdbcDaoSupport;

/**
 *
 * @author Administrator
 */
public class FileDao extends JdbcDaoSupport implements IFileDao {

    @Override
    public List getFiles(String sort, int start, int count) {
        JdbcTemplate jt = getJdbcTemplate();
        String sql = "select * from tb_file";
        return jt.query(sql, new RowMapperResultReader(new FileRowMapper()));
    }

    class FileRowMapper implements RowMapper {
        @Override
        public Object mapRow(ResultSet rs, int index) throws SQLException {
            FileBean fb = new FileBean();
            fb.setId(rs.getString("id_"));
            fb.setName(rs.getString("name_"));
            fb.setDesc(rs.getString("desc_"));
            return fb;
        }
    }
}